//节流函数
const throttle =  (func, marginTime=3000,isShowToast=true)=> {
  let lastTime = null
  return function () {
    let currentTime = + new Date()
    if (currentTime - lastTime > marginTime || !lastTime) {
      func.apply(this, arguments)  
      lastTime = currentTime
    }else{
      if(isShowToast){
        wx.showToast({
          title: '发送频率过快!',
          icon:'none',
          duration: 1000
        })
      }
    }
  }
}
//节流函数
const debounce =(fun,delay = 700) =>{
    let timeout ;
    return function (...args) {  
      // console.log('防抖函数参数',args)
      let that = this
      let _args = args
      clearTimeout(timeout)
      timeout = setTimeout(function () {
          fun.call(that, _args)
      }, delay)
  }
}
module.exports = {
  throttle : throttle,
  debounce : debounce
}
